{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.DataFrame({\n",
    "    \"A\":pd.Series(np.random.rand(10)*1000,index=pd.date_range(\"2021-12-17\",periods=10)),\n",
    "    \"B\":pd.Series(np.random.rand(10)*1000,index=pd.date_range(\"2021-12-17\",periods=10)),\n",
    "    \"C\":pd.Series(np.random.rand(10)*1000,index=pd.date_range(\"2021-12-17\",periods=10)),\n",
    "    \"D\":pd.Series(np.random.rand(10)*1000,index=pd.date_range(\"2021-12-17\",periods=10)),\n",
    "    \"E\":pd.Series(np.random.rand(10)*1000,index=pd.date_range(\"2021-12-17\",periods=10)),\n",
    "    \"F\":pd.Series(np.random.rand(10)*1000,index=pd.date_range(\"2021-12-17\",periods=10)),\n",
    "    \"G\":pd.Series(np.random.rand(10)*1000,index=pd.date_range(\"2021-12-17\",periods=10)),\n",
    "    \"H\":pd.Series(np.random.rand(10)*1000,index=pd.date_range(\"2021-12-17\",periods=10)),\n",
    "    \"I\":pd.Series(np.random.rand(10)*1000,index=pd.date_range(\"2021-12-17\",periods=10)),\n",
    "    \"J\":pd.Series(np.random.rand(10)*1000,index=pd.date_range(\"2021-12-17\",periods=10)),\n",
    "    \"K\":pd.Series(np.random.rand(10)*1000,index=pd.date_range(\"2021-12-17\",periods=10)),\n",
    "    \"L\":pd.Series(np.random.rand(10)*1000,index=pd.date_range(\"2021-12-17\",periods=10)),\n",
    "    \"M\":pd.Series(np.random.rand(10)*1000,index=pd.date_range(\"2021-12-17\",periods=10)),\n",
    "    \"N\":pd.Series(np.random.rand(10)*1000,index=pd.date_range(\"2021-12-17\",periods=10)),\n",
    "})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "      <th>F</th>\n",
       "      <th>G</th>\n",
       "      <th>H</th>\n",
       "      <th>I</th>\n",
       "      <th>J</th>\n",
       "      <th>K</th>\n",
       "      <th>L</th>\n",
       "      <th>M</th>\n",
       "      <th>N</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2021-12-17</th>\n",
       "      <td>389.367838</td>\n",
       "      <td>598.576510</td>\n",
       "      <td>295.338195</td>\n",
       "      <td>813.679401</td>\n",
       "      <td>461.444137</td>\n",
       "      <td>588.943772</td>\n",
       "      <td>958.366110</td>\n",
       "      <td>599.627061</td>\n",
       "      <td>918.602524</td>\n",
       "      <td>589.440764</td>\n",
       "      <td>316.221390</td>\n",
       "      <td>272.432374</td>\n",
       "      <td>242.811095</td>\n",
       "      <td>184.986423</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-12-18</th>\n",
       "      <td>601.207090</td>\n",
       "      <td>524.397263</td>\n",
       "      <td>487.348112</td>\n",
       "      <td>857.760660</td>\n",
       "      <td>343.077300</td>\n",
       "      <td>110.179876</td>\n",
       "      <td>238.723530</td>\n",
       "      <td>73.395828</td>\n",
       "      <td>374.047556</td>\n",
       "      <td>195.395971</td>\n",
       "      <td>556.753864</td>\n",
       "      <td>634.867878</td>\n",
       "      <td>110.458440</td>\n",
       "      <td>752.512284</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-12-19</th>\n",
       "      <td>390.394582</td>\n",
       "      <td>74.722324</td>\n",
       "      <td>931.140899</td>\n",
       "      <td>899.471089</td>\n",
       "      <td>555.716223</td>\n",
       "      <td>135.093140</td>\n",
       "      <td>511.374358</td>\n",
       "      <td>738.697487</td>\n",
       "      <td>956.106735</td>\n",
       "      <td>428.463386</td>\n",
       "      <td>861.472957</td>\n",
       "      <td>326.621550</td>\n",
       "      <td>75.598471</td>\n",
       "      <td>690.600698</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-12-20</th>\n",
       "      <td>632.007312</td>\n",
       "      <td>624.833765</td>\n",
       "      <td>417.246397</td>\n",
       "      <td>985.921632</td>\n",
       "      <td>509.805826</td>\n",
       "      <td>403.787973</td>\n",
       "      <td>842.667332</td>\n",
       "      <td>803.642380</td>\n",
       "      <td>841.180207</td>\n",
       "      <td>631.403386</td>\n",
       "      <td>159.243321</td>\n",
       "      <td>698.402363</td>\n",
       "      <td>352.688661</td>\n",
       "      <td>831.398357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-12-21</th>\n",
       "      <td>764.384338</td>\n",
       "      <td>146.324513</td>\n",
       "      <td>268.440032</td>\n",
       "      <td>317.628311</td>\n",
       "      <td>523.061653</td>\n",
       "      <td>656.636082</td>\n",
       "      <td>656.725647</td>\n",
       "      <td>955.368709</td>\n",
       "      <td>390.361822</td>\n",
       "      <td>488.763069</td>\n",
       "      <td>695.117163</td>\n",
       "      <td>2.308408</td>\n",
       "      <td>693.445753</td>\n",
       "      <td>778.627317</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-12-22</th>\n",
       "      <td>322.896467</td>\n",
       "      <td>494.138365</td>\n",
       "      <td>259.880001</td>\n",
       "      <td>345.912912</td>\n",
       "      <td>313.919203</td>\n",
       "      <td>24.673181</td>\n",
       "      <td>788.967004</td>\n",
       "      <td>596.823228</td>\n",
       "      <td>125.613743</td>\n",
       "      <td>808.174816</td>\n",
       "      <td>368.711708</td>\n",
       "      <td>917.876930</td>\n",
       "      <td>52.585522</td>\n",
       "      <td>80.598591</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-12-23</th>\n",
       "      <td>929.138076</td>\n",
       "      <td>214.783003</td>\n",
       "      <td>338.075342</td>\n",
       "      <td>285.828083</td>\n",
       "      <td>759.421303</td>\n",
       "      <td>662.854217</td>\n",
       "      <td>146.065187</td>\n",
       "      <td>241.467045</td>\n",
       "      <td>818.375042</td>\n",
       "      <td>86.531761</td>\n",
       "      <td>630.545441</td>\n",
       "      <td>284.695128</td>\n",
       "      <td>202.856668</td>\n",
       "      <td>68.602629</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-12-24</th>\n",
       "      <td>31.081394</td>\n",
       "      <td>69.780021</td>\n",
       "      <td>968.760187</td>\n",
       "      <td>960.579818</td>\n",
       "      <td>891.097190</td>\n",
       "      <td>457.830072</td>\n",
       "      <td>391.855126</td>\n",
       "      <td>286.578236</td>\n",
       "      <td>148.176194</td>\n",
       "      <td>849.590630</td>\n",
       "      <td>509.352896</td>\n",
       "      <td>766.147712</td>\n",
       "      <td>765.485566</td>\n",
       "      <td>744.916764</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-12-25</th>\n",
       "      <td>472.372358</td>\n",
       "      <td>804.642103</td>\n",
       "      <td>912.622044</td>\n",
       "      <td>809.247379</td>\n",
       "      <td>907.505962</td>\n",
       "      <td>551.828589</td>\n",
       "      <td>17.301501</td>\n",
       "      <td>460.287393</td>\n",
       "      <td>112.844118</td>\n",
       "      <td>609.700832</td>\n",
       "      <td>740.419550</td>\n",
       "      <td>858.482864</td>\n",
       "      <td>321.536407</td>\n",
       "      <td>633.272465</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2021-12-26</th>\n",
       "      <td>880.712042</td>\n",
       "      <td>948.880501</td>\n",
       "      <td>939.182363</td>\n",
       "      <td>363.785818</td>\n",
       "      <td>65.018221</td>\n",
       "      <td>465.387422</td>\n",
       "      <td>720.108312</td>\n",
       "      <td>357.612642</td>\n",
       "      <td>648.064123</td>\n",
       "      <td>365.593772</td>\n",
       "      <td>491.264776</td>\n",
       "      <td>598.784582</td>\n",
       "      <td>114.773893</td>\n",
       "      <td>319.621349</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                     A           B           C           D           E  \\\n",
       "2021-12-17  389.367838  598.576510  295.338195  813.679401  461.444137   \n",
       "2021-12-18  601.207090  524.397263  487.348112  857.760660  343.077300   \n",
       "2021-12-19  390.394582   74.722324  931.140899  899.471089  555.716223   \n",
       "2021-12-20  632.007312  624.833765  417.246397  985.921632  509.805826   \n",
       "2021-12-21  764.384338  146.324513  268.440032  317.628311  523.061653   \n",
       "2021-12-22  322.896467  494.138365  259.880001  345.912912  313.919203   \n",
       "2021-12-23  929.138076  214.783003  338.075342  285.828083  759.421303   \n",
       "2021-12-24   31.081394   69.780021  968.760187  960.579818  891.097190   \n",
       "2021-12-25  472.372358  804.642103  912.622044  809.247379  907.505962   \n",
       "2021-12-26  880.712042  948.880501  939.182363  363.785818   65.018221   \n",
       "\n",
       "                     F           G           H           I           J  \\\n",
       "2021-12-17  588.943772  958.366110  599.627061  918.602524  589.440764   \n",
       "2021-12-18  110.179876  238.723530   73.395828  374.047556  195.395971   \n",
       "2021-12-19  135.093140  511.374358  738.697487  956.106735  428.463386   \n",
       "2021-12-20  403.787973  842.667332  803.642380  841.180207  631.403386   \n",
       "2021-12-21  656.636082  656.725647  955.368709  390.361822  488.763069   \n",
       "2021-12-22   24.673181  788.967004  596.823228  125.613743  808.174816   \n",
       "2021-12-23  662.854217  146.065187  241.467045  818.375042   86.531761   \n",
       "2021-12-24  457.830072  391.855126  286.578236  148.176194  849.590630   \n",
       "2021-12-25  551.828589   17.301501  460.287393  112.844118  609.700832   \n",
       "2021-12-26  465.387422  720.108312  357.612642  648.064123  365.593772   \n",
       "\n",
       "                     K           L           M           N  \n",
       "2021-12-17  316.221390  272.432374  242.811095  184.986423  \n",
       "2021-12-18  556.753864  634.867878  110.458440  752.512284  \n",
       "2021-12-19  861.472957  326.621550   75.598471  690.600698  \n",
       "2021-12-20  159.243321  698.402363  352.688661  831.398357  \n",
       "2021-12-21  695.117163    2.308408  693.445753  778.627317  \n",
       "2021-12-22  368.711708  917.876930   52.585522   80.598591  \n",
       "2021-12-23  630.545441  284.695128  202.856668   68.602629  \n",
       "2021-12-24  509.352896  766.147712  765.485566  744.916764  \n",
       "2021-12-25  740.419550  858.482864  321.536407  633.272465  \n",
       "2021-12-26  491.264776  598.784582  114.773893  319.621349  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                      A            B            C            D            E  \\\n",
      "2021-12-17   389.367838   598.576510   295.338195   813.679401   461.444137   \n",
      "2021-12-18   990.574927  1122.973773   782.686308  1671.440062   804.521438   \n",
      "2021-12-19  1380.969510  1197.696097  1713.827206  2570.911151  1360.237661   \n",
      "2021-12-20  1623.608984  1223.953353  1835.735408  2743.153382  1408.599350   \n",
      "2021-12-21  1786.786233   845.880602  1616.827328  2203.021033  1588.583703   \n",
      "2021-12-22  1719.288117  1265.296644   945.566430  1649.462855  1346.786683   \n",
      "2021-12-23  2016.418881   855.245882   866.395375   949.369306  1596.402160   \n",
      "2021-12-24  1283.115937   778.701390  1566.715529  1592.320813  1964.437696   \n",
      "2021-12-25  1432.591828  1089.205128  2219.457572  2055.655280  2558.024455   \n",
      "2021-12-26  1384.165795  1823.302625  2820.564594  2133.613015  1863.621373   \n",
      "\n",
      "                      F            G            H            I            J  \\\n",
      "2021-12-17   588.943772   958.366110   599.627061   918.602524   589.440764   \n",
      "2021-12-18   699.123648  1197.089640   673.022889  1292.650081   784.836735   \n",
      "2021-12-19   834.216788  1708.463998  1411.720376  2248.756816  1213.300122   \n",
      "2021-12-20   649.060989  1592.765219  1615.735695  2171.334498  1255.262743   \n",
      "2021-12-21  1195.517196  2010.767337  2497.708576  2187.648764  1548.629842   \n",
      "2021-12-22  1085.097237  2288.359983  2355.834318  1357.155772  1928.341271   \n",
      "2021-12-23  1344.163480  1591.757838  1793.658983  1334.350607  1383.469647   \n",
      "2021-12-24  1145.357470  1326.887316  1124.868510  1092.164979  1744.297208   \n",
      "2021-12-25  1672.512877   555.221814   988.332675  1079.395354  1545.823224   \n",
      "2021-12-26  1475.046082  1129.264939  1104.478272   909.084435  1824.885234   \n",
      "\n",
      "                      K            L            M            N  \n",
      "2021-12-17   316.221390   272.432374   242.811095   184.986423  \n",
      "2021-12-18   872.975254   907.300251   353.269535   937.498706  \n",
      "2021-12-19  1734.448212  1233.921802   428.868006  1628.099404  \n",
      "2021-12-20  1577.470143  1659.891791   538.745572  2274.511338  \n",
      "2021-12-21  1715.833442  1027.332321  1121.732884  2300.626372  \n",
      "2021-12-22  1223.072192  1618.587701  1098.719935  1690.624265  \n",
      "2021-12-23  1694.374312  1204.880466   948.887942   927.828537  \n",
      "2021-12-24  1508.610045  1968.719770  1020.927755   894.117983  \n",
      "2021-12-25  1880.317887  1909.325704  1289.878640  1446.791858  \n",
      "2021-12-26  1741.037223  2223.415158  1201.795866  1697.810578  \n"
     ]
    }
   ],
   "source": [
    "# 对整体聚合\n",
    "r = df.rolling(window=3,min_periods=1)\n",
    "print(r.aggregate(np.sum))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2021-12-17     389.367838\n",
      "2021-12-18     990.574927\n",
      "2021-12-19    1380.969510\n",
      "2021-12-20    1623.608984\n",
      "2021-12-21    1786.786233\n",
      "2021-12-22    1719.288117\n",
      "2021-12-23    2016.418881\n",
      "2021-12-24    1283.115937\n",
      "2021-12-25    1432.591828\n",
      "2021-12-26    1384.165795\n",
      "Freq: D, Name: A, dtype: float64\n"
     ]
    }
   ],
   "source": [
    "# 对某一列聚合\n",
    "print(r[\"A\"].aggregate(np.sum))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
